<?php
header("Content-Type:application/json;charset=utf-8");
header("Access-Control-Allow-Origin:*");
if ($_SERVER["REQUEST_METHOD"]=="POST"){
//    1.准备链接数据库的配置信息
    $host = "127.0.0.1";
    $name = "root";
    $pwd = "";
    $port = "3306";
    $db = "mia";
    //2.创建链接
    $conn = new mysqli($host, $name, $pwd, $db, $port);
    //3.设置链接字符集
    mysqli_query($conn, "SET NAMES UTF8");
    //4.准备SQL语句
    $query = " SELECT *FROM `carts` WHERE `uId`='" . $_POST["uid"] . "' AND `gId`='" . $_POST["gId"] . "'";
    $resultA=$conn->query($query);
    if($resultA->num_rows>=1){
        $update=" UPDATE `carts` SET `num`='". $_POST["num"]. "', `gTotal`='".$_POST["gTotal"]."' WHERE `uId`='" . $_POST["uid"] . "' AND `gId`='" . $_POST["gId"] . "'";
        $resultB=$conn->query($update);
        if($resultB){
            print_r(json_encode(array("msg"=>"修改成功","status" => 1)));
        }else{
            print_r(json_encode(array("msg"=>"修改失败", "status" => -1)));
        }
    }
}